package com.xbts.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbts.common.annotation.Excel;
import com.xbts.common.core.domain.BaseEntity;
import com.xbts.common.utils.StringUtils;
import com.xbts.system.enums.WorkOrderStatusEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 工单对象 cn_work_order
 *
 * @author xbts
 * @date 2023-08-28
 */
@Data
@ApiModel("工单对象")
@TableName("cn_work_order")
public class CnWorkOrder extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 工单编号
     */
    @TableId
    private String orderNum;

    /**
     * 问题描述
     */
    @Excel(name = "问题描述")
    @ApiModelProperty("问题描述")
    @NotEmpty(message = "问题描述不能为空")
    private String problemDescription;

    /**
     * 问题类型（1售后问题 2产品问题）
     */
    @Excel(name = "问题类型", readConverterExp = "1=售后问题,2=产品问题")
    @ApiModelProperty("问题类型（1售后问题 2产品问题）")
    @NotNull(message = "问题类型不能为空")
    private Integer problemType;

    /**
     * 工单状态   IN_PROGRESS进行中 CLOSED已关闭
     */
    @Excel(name = "工单状态")
    @ApiModelProperty("工单状态")
    private WorkOrderStatusEnum status;

    @TableField(exist = false)
    private int unReadNum;

    @TableField(exist = false)
    private Long userId;
    @TableField(exist = false)
    private String userName;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(orderNum), "cwo.order_num", orderNum);
        queryWrapper.like(StringUtils.isNotEmpty(problemDescription), "cwo.problem_description", problemDescription);
        return queryWrapper;
    }
}
